package com.registration.consumer;

import com.rabbitmq.client.Channel;
import com.registration.entity.ResultEntity;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.util.SerializationUtils;

import java.io.IOException;

/**
 * 定义一个Bean，消费者，监听队列，定义处理消息的方法
 */
@Component
public class ListenerConsumer {

    /*//指定监听队列
    @RabbitListener(queues = "registration")
    //String msg,   消息体
    //Message message 消息对象
    //com.rabbitmq.client.Channel channel  信道
    public void registration(byte[] bs, Message message, Channel channel) throws IOException {
        System.out.println("处理消息队列消息");
        System.out.println("msg:"+bs);
        ResultEntity deserialize = (ResultEntity) SerializationUtils.deserialize(bs);
        System.out.println(deserialize);
        System.out.println("-----------------");
    }*/


    //指定死信监听队列
    @RabbitListener(queues = "registration-dlx")
    //String msg,   消息体
    //Message message 消息对象
    //com.rabbitmq.client.Channel channel  信道
    public void registrationdlx(byte[] bs, Message message, Channel channel) throws IOException {
        System.out.println("死信消息队列消息");
        System.out.println("msg:"+bs);
        ResultEntity deserialize = (ResultEntity) SerializationUtils.deserialize(bs);
        System.out.println(deserialize);
        System.out.println("-----------------");
    }
}
